<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./node_modules/vue/dist/vue.js"></script>
  </head>

  <body>
    <div id="app">
      {{msg}}

      <Foo v-if="isShow"></Foo>
    </div>
    <script>
      const Bar = {
        template: `<div>Bar</div>`,

        // 创建
        beforeCreate() {
          console.log("bar - before - create");
        },
        created() {
          console.log("bar -created");
        },

        // 挂载
        beforeMount() {
          console.log("bar -before- mount");

          // ? 可以在这里获取吗？
          // this.$el;
        },

        mounted() {
          console.log("bar -mounted");
          // this.$el;
          // children
        },

        // 更新
        beforeUpdate() {
          console.log(this.$el);
          console.log("bar -before - update");
        },

        updated() {
          console.log("bar -updated");
          console.log(this.$el);
        },

        // 销毁
        beforeDestroy() {
          console.log("bar - before - destroy");
        },

        destroyed() {
          console.log("bar -destroyed");
        },
      };

      // hook 钩子
      const Foo = {
        components: {
          Bar,
        },

        template: `<div>Foo
          
            {{count}}
            <button @click="count++">click</button>
            <Bar></Bar>
          
          </div>`,
        data() {
          return {
            count: 1,
          };
        },
        // 创建
        beforeCreate() {
          console.log("before - create");
        },
        created() {
          console.log("created");
        },

        // 挂载
        beforeMount() {
          console.log("before- mount");

          // ? 可以在这里获取吗？
          // this.$el;
        },

        mounted() {
          console.log("mounted");
          // this.$el;
          // children
        },

        // 更新
        beforeUpdate() {
          console.log(this.$el);
          console.log("before - update");
        },

        updated() {
          console.log("updated");
          console.log(this.$el);
        },

        // 销毁
        beforeDestroy() {
          console.log("before - destroy");
        },

        destroyed() {
          console.log("destroyed");
        },
      };

      const app = new Vue({
        el: "#app",
        components: {
          Foo,
        },
        data: {
          msg: "hello ",
          isShow: true,
        },
      });
    </script>
  </body>
</html>
